'use client';


import { Grade } from '@/data/prisma';
import EditableTable from '@/pao/web/dataEdit/dateEditEditableTable';
import { ISelectableControlProps, SelectableTable } from '@/pao/web/dataEdit/dataEditSelectableTable';
import { ProColumnType } from '@ant-design/pro-components';

import { addRow, deleteRow, editRow, query } from './service';

const columns: ProColumnType<Grade>[] = [
    {
        title: '编号',
        dataIndex: 'code',
        fixed: 'left',
        sorter: true,
        width: '80px',
    },
    {
        title: '名称',
        dataIndex: 'name',
        sorter: true,
        fixed: 'left',
        width: '150px',
    },    
		{
			index: 3,
			title: '阶段',
			dataIndex: 'stage',
			valueType: 'select',
			valueEnum: {
				0: { text: '幼儿园', status: 'success' },
				1: { text: '小学', status: 'success' },
				2: { text: '初中', status: 'success' },
				3: { text: '高中', status: 'success' },
				4: { text: '大学', status: 'success' },
			},
			sorter: true,
			width: '150px',
		},
    {
        title: '备注',
        dataIndex: 'comments',
        sorter: true,
        width: 'auto',
    },
];

const config = {
    headerTitle: '年级',
    tooltip: '修改年级信息',
}

export default function GradeControl() {
    return <EditableTable<Grade> columns={columns} rowKey="id" config={config} deleteRow={deleteRow} query={query} editRow={editRow} addRow={addRow}/>
}


const selectColumns: ProColumnType<Grade>[] = [
	{
			title: '编号',
			dataIndex: 'code',
			fixed: 'left',
			sorter: true,
			width: '40px',
	},
	{
			title: '名称',
			dataIndex: 'name',
			sorter: true,
			fixed: 'left',
			width: '80px',
	}
];

export function GradeSelectControl({onSelectRow}: ISelectableControlProps<Grade>) {
	return <SelectableTable onSelectRow={onSelectRow} columns={selectColumns} rowKey="id" query={query}/>
}